const {cloud} = getApp();
Page({
  data:{
    tle:'权益领取',
    subTle:'中奖信息',
    miniProductID:[
      1,2,3,4
    ],      //小程序id列表

    miniProductIDIndex:"",   //小程序id下标
    pageNo:1,
    pageSize:1,


    tltArr:[
      {title:'淘宝会员名称',id:'userNick'},
      {title:'奖品名称',id:'prizeName'},
      {title:'留资信息',id:'receiverAddress'},
      {title:'发奖类型',id:'type'},
      {title:'奖品类型',id:'type'},
      {title:'获奖时间',id:'createTime'}
    ],
    drawData:[
      {
        username:'猪沛购物拉',
        draw:'iphone12',
        address:'广东广州黄埔区大沙东319号保利中誉2501',
        formType:'排行榜',
        drawType:'实物',
        drawTime:'2021-01-19 15:56:00'
      },
      {
        username:'猪沛购物拉',
        draw:'iphone12',
        address:'广东广州黄埔区大沙东319号保利中誉2501',
        formType:'排行榜',
        drawType:'优惠券',
        drawTime:'2021-01-19 15:56:00'
      }
    ],
    test:[
      { value: 'id', label: 'Id' },
      { value: 'title', label: 'Title' },
      { value: 'time', label: 'Time' },
    ]
  },

  //小程序id选择器事件
  itemclick(e){

    this.setData({
      miniProductIDIndex:e.detail.value
    })
    //console.info("id",e.detail.value)

  },

  //input onchange
  changInput(e){

    let val = e.detail.value;

    let obj = e.target.dataset.id;

    let lin = this.data.prizeSearchVo

    lin[obj] = val;

    this.setData({
      prizeSearchVo:lin
    })

    console.log(this.data.prizeSearchVo)

  
  },

  //日期

  changeDate(e){

    let val = e.detail.value;

    let lin = this.data.prizeSearchVo;

    lin.startTime=val[0];
    lin.endTime=val[1]

    // console.log(this.data.prizeSearchVo);

  },
  

  //第多少页
  onPageChange(e){

    console.log(e);
    this.setData({
      pageNo:e.detail.value
    })



    // let val= this.data.prizeSearchVo

    // val.pageNo=e.detail.value

    // this.setData({
    //   prizeSearchVo:val
    // })

    // console.log(this.data)
    this.getRlreceive()
  },


  //获取奖品列表
  getRlreceive(){
    cloud.application.httpRequest({
      'path': '/api/b/prizeList',
      'method': 'POST',
      'headers':{ "Content-Type":"application/json"},
      'params':{ },
      'body':{ mini_app_id: this.data.miniProductIDIndex,pageNo: this.data.pageNo,pageSize: this.data.pageSize,},
    }).then(ress => {

      console.info("奖品列表",ress);
      this.setData({ drawData: ress.data.list, pageData: ress.data})
      
    })
  },

  //获取小程序名称
  getAPPname(){
    cloud.application.httpRequest({
      'path': `/api/b/getAppName`,
      'method': 'GET',
      'headers':{ "Content-Type":"application/json"},
      'params':{  },
      'body':{ },
    }).then(ress => {

      console.info("获取小程序名称",ress);

      if(ress.code==-1){
        my.alert({content:ress.msg})
      }else{
        this.setData({ miniProductID: ress.data})
      }
    })
  },

  onLoad() {

  
    //小程序列表
    this.getAPPname();

    //奖品列表
    this.getRlreceive();
    


  },
});
